﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ClientApplication
{
    public partial class Admin3 : Form, IAdmin3
    {
        public event CopyContestantsEventHandler CopyContestants = null;
        private int gender { get; set; }


        public Admin3()
        {
            InitializeComponent();
            bAdd.Enabled = false;
        }

        public void SetGender(int genderData)
        {
            this.gender = genderData;
        }

        private void bAdd_Click(object sender, EventArgs e)
        {
            try
            {
                Contestant toAdd = new Contestant(int.Parse(textBoxID.Text), textBoxName.Text, int.Parse(textBoxAge.Text), gender, textBoxNationality.Text, 0);

                CopyContestantsEventArgs args = new CopyContestantsEventArgs(toAdd);
                if (CopyContestants != null)
                    CopyContestants(this, args);

                this.textBoxID.Clear();
                this.textBoxName.Clear();
                this.textBoxAge.Clear();
                this.textBoxNationality.Clear();
            }
            catch(System.FormatException e2)
            {
                MessageBox.Show(e2.InnerException + "Wrong input format. Retry.");
            }
        }
        private void Form3_Load(object sender, EventArgs e)
        {

        }

        private void bCopyContestants_Click(object sender, EventArgs e)
        {
        }

        private void listViewContestantsForm3_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void CheckBoxes()
        {
            if (textBoxID.Text.Trim().Length > 0
                && textBoxName.Text.Trim().Length > 0
                && textBoxAge.Text.Trim().Length > 0
                && textBoxNationality.Text.Trim().Length > 0)
            {
                bAdd.Enabled = true;
            }
            else
            {
                bAdd.Enabled = false;
            }
        }

        private void textBoxID_TextChanged(object sender, EventArgs e)
        {
            CheckBoxes();
        }

        private void textBoxName_TextChanged(object sender, EventArgs e)
        {
            CheckBoxes();
        }

        private void textBoxAge_TextChanged(object sender, EventArgs e)
        {
            CheckBoxes();
        }

        private void textBoxGender_TextChanged(object sender, EventArgs e)
        {
            CheckBoxes();
        }

        private void textBoxNationality_TextChanged(object sender, EventArgs e)
        {
            CheckBoxes();
        }

    }
}
